var ACTION = require("../../base/action");
var utils = require("../../utils/utils");
var ocrGml = require("../../utils/ocrGml");
var actionRead = new ACTION("阅读");
var readArticle = require("../appCommon/readArticle");
actionRead.startRead = function () {
  var content = ["小时前", "天前", "周前", "前天", "月前"];
  var ocrItem = ocrGml.findTextOne(
    content,
    true,
    null,
    5,
    (device.height / 10) * 2
  );
  if (ocrItem) {
    console.log("找到-" + ocrItem.text + "-");
    utils.clickOcrItem(ocrItem);
    sleep(utils.getRandom(3, 5, 1000));
    var ocrItem = ocrGml.captureExistOne(["全屏"], true);
    if (ocrItem) {
      var baseSpan = 10;
      var span = utils.getRandom(baseSpan, baseSpan + 30);
      console.log("开始看视频-" + span + "-s");
      sleep(span * 1000);
      back();
      sleep(utils.getRandom(2, 4, 1000));
      return;
    }
    var baseSpan = 40;
    var span = utils.getRandom(baseSpan, baseSpan + 5);
    console.log("开始看文章-" + span + "-s");
    readArticle(span);
    back();
    sleep(utils.getRandom(2, 4, 1000));
    return;
  }
};

actionRead.exec = function () {
  this.startRead();
};

module.exports = actionRead;
